package com.tanguy.user.ui.main.adapter

import android.view.View
import cn.sinata.xldutils_kotlin.callPhone
import com.tanguy.user.R
import com.tanguy.user.base.JustAdapter
import com.tanguy.user.bean.orde.OrderBean
import com.tanguy.user.utlis.StackManager
import com.tanguy.user.utlis.TimeUtils
import com.tanguy.user.utlis.extend.*


/**
 * Created by dab on 2017/10/23 0023 16:01
 */
class TripOrderAdapter(data: ArrayList<OrderBean>) : JustAdapter<OrderBean>(data, R.layout.item_order_trip) {
    override fun bind(itemView: View, data: OrderBean, position: Int) {
        itemView.apply {
            setText(R.id.tv_type,data.typeString).setDrawable(left = data.typeImg)
            setText(R.id.tv_state,data.stateString)
            setText(R.id.tv_start,data.departure)
            setText(R.id.tv_end,data.bourn)
            setText(R.id.tv_time,data.bybustime.toTimeString(TimeUtils.TIME_YYYY_MM_DD_HH_MM_01))
            setBackground(R.id.view_background,data.backgroundImg)
            click(R.id.tv_call_phone){ StackManager.currentActivity().callPhone(data.phone) }
            visibility(R.id.tv_cancel, data.state < 4)
            click(R.id.tv_cancel) {
                cancel(data,position)

//                itemClick?.invoke(R.id.tv_cancel,position,data)
            }
        }

    }

    private fun cancel(data: OrderBean, position: Int) {
        cancelOrder(data.id.toString()) {
            mDatas.remove(data)
            notifyItemRemoved(position)
            notifyItemRangeChanged(position,mDatas.size)
        }
    }

}